package org.ycty.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.ycty.deale.ImgSaveOrUp;
import org.ycty.entity.Imgs;

public class SaveImg extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		request.setCharacterEncoding("UTF-8");
		
		 	int id = (request.getParameter("id")== null)?0:(Integer.parseInt(request.getParameter("id")));
			String pathname = request.getParameter("pathname");
			String webname = request.getParameter("webname");
			String weburl = request.getParameter("weburl");
			String imgw = request.getParameter("imgw");
			String imgh = request.getParameter("imgh");
			String khdm = request.getParameter("khdm");
			String bmgs = request.getParameter("bmgs");
			String other = request.getParameter("other");
			
			Imgs imgs = new Imgs();
			if(id!=0){
				imgs.setId(id);
			}
			imgs.setPathname(pathname);
			imgs.setWebname(webname);
			imgs.setWeburl(weburl);
			imgs.setImgw(imgw);
			imgs.setImgh(imgh);
			imgs.setKhdm(khdm);
			imgs.setBmgs(bmgs);
			imgs.setOther(other);
			
			Boolean b = new ImgSaveOrUp().saveOrUpImg(imgs);
			
			if(b){
				request.setAttribute("msg", "OK");
				request.getRequestDispatcher("imgs.jsp").forward(request, response);
			}else{
				request.setAttribute("msg", "FAIL");
				request.getRequestDispatcher("imgs.jsp").forward(request, response);
			}
	}

}




















